package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

public class Main {
	private static final ResourceBundle BUNDLE = ResourceBundle
			.getBundle("gui.messages"); //$NON-NLS-1$

	private JFrame frame;
	private JPanel panel;
	private JPanel panel_1;
	private JPanel panel_2;
	private JLabel lblNewLabel;
	private JPanel panel_3;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JPanel panel_4;
	private JScrollPane scrollPane;
	private JTable table;
	private JLabel lblClassname;
	private JTextField textField;
	private JTextField textField_1;
	private JPanel panel_5;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main window = new Main();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Main() {
		try {
			UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
		}
		initialize();
		GuiEventHandler.onCreated(this);
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBackground(Color.WHITE);
		frame.getContentPane().setBackground(Color.WHITE);
		frame.setTitle(BUNDLE.getString("Main.frame.title")); //$NON-NLS-1$
		frame.setBounds(100, 100, 600, 450);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(getPanel_3(), BorderLayout.NORTH);
		frame.getContentPane().add(getPanel_1_1(), BorderLayout.CENTER);
		frame.getContentPane().add(getPanel_2_1(), BorderLayout.SOUTH);
	}

	protected JFrame getFrame() {
		return frame;
	}

	protected JPanel getPanel_3() {
		if (panel == null) {
			panel = new JPanel();
			panel.setBackground(Color.WHITE);
			panel.add(getLblNewLabel());
			panel.add(getTextField());
			panel.add(getLblClassname());
			panel.add(getTextField_1());
		}
		return panel;
	}

	protected JPanel getPanel_1_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setBackground(Color.WHITE);
			panel_1.setBorder(new TitledBorder(UIManager
					.getBorder("TitledBorder.border"), "Columns",
					TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panel_1.setLayout(new BorderLayout(0, 0));
			panel_1.add(getPanel_4(), BorderLayout.SOUTH);
			panel_1.add(getScrollPane(), BorderLayout.CENTER);
		}
		return panel_1;
	}

	protected JPanel getPanel_2_1() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setBackground(Color.WHITE);
			panel_2.setLayout(new BorderLayout(0, 0));
			panel_2.add(getPanel_3_1(), BorderLayout.EAST);
			panel_2.add(getPanel_5(), BorderLayout.CENTER);
		}
		return panel_2;
	}

	protected JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel(
					BUNDLE.getString("Main.lblNewLabel.text_1")); //$NON-NLS-1$
		}
		return lblNewLabel;
	}

	protected JPanel getPanel_3_1() {
		if (panel_3 == null) {
			panel_3 = new JPanel();
			panel_3.setBackground(Color.WHITE);
			panel_3.setBorder(new EmptyBorder(0, 20, 3, 20));
			panel_3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
			panel_3.add(getBtnNewButton());
			panel_3.add(getBtnNewButton_1());
		}
		return panel_3;
	}

	protected JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton(
					BUNDLE.getString("Main.btnNewButton.text")); //$NON-NLS-1$
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					GuiEventHandler.onGenerateButtonClick(Main.this);
				}
			});
		}
		return btnNewButton;
	}

	protected JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton(
					BUNDLE.getString("Main.btnNewButton_1.text")); //$NON-NLS-1$
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					GuiEventHandler.onCancelButtonClick(frame);
				}
			});
		}
		return btnNewButton_1;
	}

	protected JPanel getPanel_4() {
		if (panel_4 == null) {
			panel_4 = new JPanel();
			panel_4.setBackground(Color.WHITE);
		}
		return panel_4;
	}

	protected JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable_1());
		}
		return scrollPane;
	}

	@SuppressWarnings("serial")
	protected JTable getTable_1() {
		if (table == null) {
			table = new JTable();
			table.setModel(new DefaultTableModel(new Object[][] { { "1", "",
					"", "" }, }, new String[] { "", "Name", "Type", "" }) {
				boolean[] columnEditables = new boolean[] { false, true, true,
						true };

				public boolean isCellEditable(int row, int column) {
					return columnEditables[column];
				}
			});
			table.getColumnModel().getColumn(0).setPreferredWidth(30);
			table.getColumnModel().getColumn(1).setPreferredWidth(150);
			table.getColumnModel().getColumn(2).setPreferredWidth(40);
			table.getColumnModel().getColumn(3).setPreferredWidth(220);
			table.setCellSelectionEnabled(true);
			table.setColumnSelectionAllowed(true);
			table.setSurrendersFocusOnKeystroke(true);
			table.setShowVerticalLines(true);
			table.setShowHorizontalLines(true);
			table.setRowHeight(31);
			table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
		}
		return table;
	}

	protected JLabel getLblClassname() {
		if (lblClassname == null) {
			lblClassname = new JLabel(
					BUNDLE.getString("Main.lblClassname.text")); //$NON-NLS-1$
			lblClassname.setForeground(new Color(255, 0, 0));
		}
		return lblClassname;
	}

	protected JTextField getTextField() {
		if (textField == null) {
			textField = new JTextField();
			textField.setText("");
			textField.setColumns(10);
		}
		return textField;
	}

	protected JTextField getTextField_1() {
		if (textField_1 == null) {
			textField_1 = new JTextField();
			textField_1.setText("");
			textField_1.setColumns(20);
		}
		return textField_1;
	}

	protected JPanel getPanel_5() {
		if (panel_5 == null) {
			panel_5 = new JPanel();
			panel_5.setBorder(new EmptyBorder(0, 20, 0, 0));
			panel_5.setBackground(Color.WHITE);
			panel_5.setLayout(new BorderLayout(0, 0));
			panel_5.add(getLblNewLabel_1(), BorderLayout.NORTH);
			panel_5.add(getLblNewLabel_2(), BorderLayout.CENTER);
		}
		return panel_5;
	}

	protected JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel(
					BUNDLE.getString("Main.lblNewLabel_1.text")); //$NON-NLS-1$
			lblNewLabel_1.setForeground(Color.GRAY);
		}
		return lblNewLabel_1;
	}

	protected JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel(
					BUNDLE.getString("Main.lblNewLabel_2.text")); //$NON-NLS-1$
			lblNewLabel_2.setForeground(Color.GRAY);
		}
		return lblNewLabel_2;
	}

}